package com.nwpu.am.service.impl;

import com.nwpu.am.mapper.RuleMapper;
import com.nwpu.am.pojo.dto.RuleDTO;
import com.nwpu.am.pojo.entity.Rule;
import com.nwpu.am.service.RuleService;
import com.nwpu.am.utils.id_generator.IdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * RuleServiceImpl
 *
 * @author Fbf
 * @version 1.0
 * {@code @date} 2024/6/6
 */
@Service
@Slf4j
public class RuleServiceImpl implements RuleService {
    @Resource
    private RuleMapper ruleMapper;
    @Resource
    IdGenerator idGenerator;

    @Override
    public ArrayList<Rule> getAllRule() {
        return ruleMapper.selectAllRule();
    }

    @Override
    public int addRule(RuleDTO ruleDTO) {
        long id = idGenerator.nextId();
        Rule rule = Rule.builder()
                .ruleId(id)
                .premiseKnowledgeId(ruleDTO.getPremiseKnowledgeId())
                .conclusionKnowledgeId(ruleDTO.getConclusionKnowledgeId())
                .probability(ruleDTO.getProbability())
                .build();
        return ruleMapper.addRule(rule);
    }

    @Override
    public int deleteRule(long ruleId){
        return ruleMapper.deleteRule(ruleId);
    }

    @Override
    public Rule selectById(long ruleId){
        return ruleMapper.selectById(ruleId);
    }
}
